package bigraph.figure;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;

public class SiteFigure extends Figure {
	  
	public static final int SITE_FIGURE_DEFWIDTH = 100;
	public static final int SITE_FIGURE_DEFHEIGHT = 100;
	
	private Label labelName = new Label();
	private XYLayout layout;
	Figure container;
	RoundedRectangle shape;
	
	public SiteFigure() {
		layout = new XYLayout();
		setLayoutManager(layout);
		container = new Figure();
		container.setLayoutManager(new XYLayout());
		add(container);
		labelName.setForegroundColor(ColorConstants.darkGray);
		labelName.setBounds(new Rectangle(5,5,50,20));
		labelName.setLabelAlignment(PositionConstants.LEFT);
		container.add(labelName,-1);
		
		
		shape = new RoundedRectangle();
		shape.setCornerDimensions(new Dimension(15,15));
		shape.setLineStyle(SWT.LINE_DASH);
		shape.setLineWidth(2);
		shape.setBackgroundColor(ColorConstants.red);
		shape.setAlpha(40);
		shape.setFill(true);
		add(shape);
		setOpaque(false);	
	}

	public void setName(String text) {
		labelName.setText(text);
	}

	public void setLayout(Rectangle rect) {
		if(getParent()==null) {
			this.setBounds(rect);
			container.setBounds(rect);
			shape.setBounds(rect);
		}
		else {
			Point point = getParent().getBounds().getLocation();
			Rectangle childRec = new Rectangle(point.x + rect.x, point.y + rect.y, rect.width, rect.height);
			this.setBounds(childRec);
			container.setBounds(childRec);
			shape.setBounds(childRec);
		}
	}
	 
    public void setColor(Color color) {
    	shape.setBackgroundColor(color);
    }
	
    @Override
    public void add(IFigure figure, Object constraint, int index) {
    	// TODO Auto-generated method stub
    	super.add(figure, constraint, -1);
    }
	
}
